package com.abhinav.generics;

import java.util.ArrayList;
import java.util.Collection;

public class Pair<E> {
	private E obj1, obj2;

	public Pair(E element1, E element2) {
		obj1 = element1;
		obj2 = element2;
	}

	public E getFirstObject() {
		return obj1;
	}

	public E getSecondObject() {
		return obj2;
	}

	public static <T> void filter(Collection<T> in, Collection<T> out) {
		boolean flag = true;
		for (T obj : in) {
			if (flag) {
				System.out.println("****** adding :" + obj);
				out.add(obj);
			}
			flag = !flag;
		}
	}

	public static <T extends Comparable> T max(T obj1, T obj2) {
		if (obj1.compareTo(obj2) > 0) {
			return obj1;
		}
		return obj2;
	}

	public static void main(String[] args) {
		// Pair<Double> aPair = new Pair<Double>(new Double(1), new Double(2));
		// System.out.println(aPair.getFirstObject() + " : " +
		// aPair.getSecondObject());
		//
		// Pair<Object> objPair = new Pair<Object>(new Integer(1), new
		// Integer(2));
		// System.out.println(objPair.getFirstObject() + " : " +
		// objPair.getSecondObject());

		ArrayList<Integer> lst1 = new ArrayList<Integer>();
		lst1.add(1);
		lst1.add(2);
		lst1.add(3);

		ArrayList<Integer> lst2 = new ArrayList<Integer>();
		ArrayList<Double> dblLst = new ArrayList<Double>();

		ArrayList<Integer> lst3 = new ArrayList<Integer>();
		ArrayList lst = new ArrayList();
		lst.add("hello");

		filter(lst, lst3);
		System.out.println(lst3.size());
		System.out.println(lst3.get(0));

		/*
		 * for (Integer val : lst3) { System.out.println(val); }
		 */
		
		System.out.println(max(new Integer(1), new Integer(4)));
	}

}
